home *** CD-ROM | disk | FTP | other *** search
- unit OutlookU;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses
- ComObj;
-
- procedure SendMail(const Subject, MessageText, MailFromAddress,
- MailToAddress: String; const Attachments: array of String);
- var
- Outlook, Mail, Recipient: Variant;
- I: Integer;
- const
- olMailItem = 0;
- const
- olOriginator = $00000000;
- olTo = $00000001;
- begin
- Outlook := CreateOleObject('Outlook.Application');
- Mail := Outlook.CreateItem(olMailItem);
- Recipient := Mail.Recipients.Add(MailToAddress);
- Recipient.Type := olTo;
- Recipient := Mail.Recipients.Add(MailFromAddress);
- Recipient.Type := olOriginator;
- for I := 1 to Mail.Recipients.Count do
- Mail.Recipients[I].Resolve;
- Mail.Subject := Subject;
- Mail.Body := MessageText;
- for I := Low(Attachments) to High(Attachments) do
- Mail.Attachments.Add(Attachments[I]);
- Mail.Save;
- Mail.Send
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- SendMail('Subject', 'Message text', 'clinic@blong.com',
- 'chrisf@itecuk.com', ['c:\autoexec.bat'])
- end;
-
- end.
-